package com.tencent;

/**
 * @className: com.tencent.DoubleNode
 * @description:
 * @author: tong.li
 * @createTime: 2023/2/22 20:42
 * @copyright: Tongcheng-Elong Holdings Limited
 */
public class DoubleNode {

    static class Node {
        private Node pre;

        private Node next;

        private Integer data;

        public Node(Integer data) {
            this.data = data;
        }
    }


    public static void main(String[] args) {
        Node node1 = new Node(1);
        Node node2 = new Node(2);
        Node node3 = new Node(3);
        node1.next = node2;
        node2.next = node3;
        node2.pre = node1;
        node3.pre = node2;
        System.out.println(node1);
        final Node rever = rever(node1);
        System.out.println(rever);
    }

    /**
     * 1 2-3-4
     * @param head
     * @return
     */
    public static Node rever(Node head) {
        Node pre = null;
        Node next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            head.pre = next;
            pre = head;
            head = next;
        }
        return pre;
    }


}
